package com.mec.beans.y2013.util;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class FileUploadUtil {

	private FileUploadUtil(){
		sdf = new SimpleDateFormat();
	}
	
	public static FileUploadUtil getInstance(){
		return instance;
	}
	
	/**
	 * @return a string 
	 */
	public String getDateAsPath(){
		return getDateAsPath(DEFAULT_DATE_PATH_PATTERN);
	}
	
	/**
	 * <pre>
	 * Usage:
	 * 1, INPUT: pattern="yyyy/MM/dd";
	 * 	OUTPUT: 2013/03/29 (as today is 2013-03-29);
	 * 2, INPUT: patter="yyyy-MM-dd_HHmmss";
	 * 	returns: 2013-03-29_200810 (as current time is 2013-03-29 20:08:10)
	 * 3, 
	 * </pre>
	 * @param pattern pattern string that sets the date path pattern;
	 * @return the date path;
	 * @since 2013-03-29
	 * @version: 1.0
	 */
	public String getDateAsPath(String pattern){
		if(null == pattern || pattern.trim().isEmpty()){
			pattern = DEFAULT_DATE_PATH_PATTERN;
		}
		sdf.applyPattern(pattern);
		
		String retval = "";
		Date date = new Date();
		retval = sdf.format(date);
		return retval;
	}
	
	private SimpleDateFormat sdf;
	private static final String DEFAULT_DATE_PATH_PATTERN = "yyyy/MM/dd";
	private static final FileUploadUtil instance = new FileUploadUtil();
	private static final Logger logger = Logger.getLogger(FileUploadUtil.class);
}
